package com.example.midushop.controller;

import com.example.midushop.entity.product.find.GetProduct;
import com.example.midushop.mapper.product.find.GetProductMapper;
import com.example.midushop.service.brand.impl.BrandServiceImpl;
import com.example.midushop.service.product.impl.GetProductServictImpl;
import com.example.midushop.util.R;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品查询服务接口控制器类
 * */
@RestController
@RequestMapping("/getProductAll")
public class GetProductAll {
    @Autowired
    GetProductServictImpl getProductMapper;   // 接口注入

    /**根据编号以及名称查询所有品牌信息，若编号为空则查询所有*/
    @GetMapping("/getProduct")
    public PageInfo<GetProduct> getProduct(@RequestParam(required = false,defaultValue ="0") int is_marketable,
            @RequestParam(required = false) long spu_id, @RequestParam(required = false,defaultValue ="") String spu_name,
                                           @RequestParam(required = false,defaultValue ="") String categoryone_name,
                                           @RequestParam(required = false,defaultValue ="") String categorytwo_name,
                                           @RequestParam(required = false,defaultValue ="") String categorythree_name,
                                           @RequestParam(required = false,defaultValue ="") String brand_name,
                                           @RequestParam(required = false) int times, @RequestParam(required = false) int price_order,
                                           @RequestParam(required = false) int sales_volume_order, @RequestParam(required = false) int priceOne,
                                           @RequestParam(required = false) int priceTwo, @RequestParam(required = false,defaultValue = "1") int index, @RequestParam(required = false,defaultValue = "10") int sum){
        System.out.println(is_marketable);
        String[] attr = new String[0];
        if(categorytwo_name.equals("[]") || categorytwo_name.equals("")){
           attr = new String[1];
           attr[0] ="";
        }else{
            attr = categorytwo_name.split(",");
        }
        return getProductMapper.GetProductAll(is_marketable,spu_id,spu_name,categoryone_name,attr,categorythree_name,brand_name,times, price_order,sales_volume_order,priceOne,priceTwo,index,sum);
    };



}
